package com.ms.auction.goods.ctrl;

import com.ms.auction.common.module.customer.FollowRecord;
import com.ms.auction.common.module.goods.AuctionGoods;
import com.ms.auction.common.module.goods.com.*;
import com.ms.auction.goods.feign.IAuctionGoodsService;
import com.ms.auction.utils.respons.Result;
import com.ms.auction.utils.respons.ResultBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 拍品首頁
 * </p>
 *
 * @author MaHC
 * @since 2019-07-11
 */
@Slf4j
@RestController
@RequestMapping("/auctionGoods")
public class AuctionGoodsController {

    @Autowired
    private IAuctionGoodsService iAuctionGoodsService;

    /**
     * 查询拍品详情
     *
     * @param auctionGoods
     * @author MaHC
     * @return
     */
    @PostMapping("/getGoodsDetailById")
    public Result getGoodsDetailById(@RequestBody AuctionGoods auctionGoods) {
        log.info("查询拍品详情接口，接收参数,param --> {}",auctionGoods);
        if (auctionGoods == null || auctionGoods.getId() == null) {
            return ResultBuilder.errorInfo("参数错误");
        }
        AuctionGoodsExt auctionGoodsExt = iAuctionGoodsService.getGoodsDetailById(auctionGoods);
        log.info("查询拍品详情接口，返回前端参数打印----->{}",auctionGoodsExt);
        return ResultBuilder.success(auctionGoodsExt);
    }

    /**
     * 详情页中我的出价
     *
     * @param auctionGoods
     * @author MaHC
     * @return
     */
    @PostMapping("/getMarkupRecord")
    public Result getMarkupRecord(@RequestBody AuctionGoods auctionGoods) {
        log.info("详情页面我的出价接口，接收参数,param --> {}",auctionGoods);
        if (auctionGoods.getCustomerId() == null || auctionGoods.getId() == null) {
            return ResultBuilder.errorInfo("参数错误");
        }
        List<MyRecord> markupRecord1 = iAuctionGoodsService.getMarkupRecord(auctionGoods);
        log.info(markupRecord1.toString());
        return ResultBuilder.success(markupRecord1);
    }

    /**
     * 客户添加或取消关注
     *
     * @param followRecord
     * @author MaHC
     * @return
     */
    @PostMapping("/addFollow")
    public Result addFollow(@RequestBody FollowRecord followRecord) {
        log.info("详情页面客户添加或取消关注接口，接收参数,param --> {}",followRecord);
        if (followRecord == null || followRecord.getCustomerId() == null || followRecord.getGoodId() == null || followRecord.getFollowFlag() == null) {
            return ResultBuilder.errorInfo("参数错误");
        }
        return ResultBuilder.errorInfo(iAuctionGoodsService.addFollow(followRecord));
    }

    /**
     * 已拍下客户信息
     *
     * @param goodsId
     * @auchor MaHC
     * @return
     */
    @PostMapping("/getSuccessPat")
    public Result getSuccessPat(Integer goodsId){
        log.info("详情页面获取已拍下客户信息接口，接收参数,param --> {}",goodsId);
        if (goodsId==null){
            return ResultBuilder.errorInfo("参数错误");
        }


        AlreadyTake alreadyTake = iAuctionGoodsService.getSuccessPat(goodsId);
        if (alreadyTake == null){
            return ResultBuilder.errorInfo("错误");
        }
        return ResultBuilder.success(alreadyTake);
    }

    /**
     * 查询已经开始拍卖的拍品
     *
     * @param homeReceive
     * author MaHC
     * @return
     */
    @RequestMapping(value = "/proceedAuctionGoods", method = RequestMethod.POST)
    public Result proceedAuctionGoods(@RequestBody HomeReceive homeReceive) {
        log.info("首页已经开始拍卖的拍品接口，接收参数,param --> {}",homeReceive);
        List<ProceeTre> mapIPage = iAuctionGoodsService.proceedAuctionGoods(homeReceive);
        return ResultBuilder.success(mapIPage);
    }

}
